//
//  CJPageControl.m
//  CJUIKitDemo
//
//  Created by ciyouzen on 2019/11/22.
//  Copyright © 2019年 dvlproad. All rights reserved.
//

#import "CJPageControl.h"

static CGFloat const kDotWidth = 5;     // 圆点宽
static CGFloat const kDotHeight = 5;    // 圆点高
static CGFloat const kDotMagrin = 5;    // 圆点宽

@implementation CJPageControl

- (void)layoutSubviews
{
    [super layoutSubviews];
    //计算圆点间距
    CGFloat marginX = kDotWidth + kDotMagrin;
    
    //计算整个pageControll的宽度
    CGFloat newW = (self.subviews.count - 1 ) * marginX;
    CGFloat originX = (self.frame.size.width - newW)/2;
    
    //遍历subview,设置圆点frame
    for (int i=0; i<[self.subviews count]; i++) {
        UIImageView *dot = [self.subviews objectAtIndex:i];
        if (i == self.currentPage) {
            [dot setFrame:CGRectMake(originX + i * marginX, dot.frame.origin.y, kDotWidth, kDotHeight)];
        } else {
            [dot setFrame:CGRectMake(originX + i * marginX, dot.frame.origin.y, kDotWidth, kDotHeight)];
        }
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
